package com.library.gq.servce.impl;


import com.library.gq.dao.imlp.InsertDaoImpl;
import com.library.gq.entity.InsertEntity;
import com.library.gq.servce.InsertServce;
import com.library.gq.util.Page;

import java.util.List;
import java.util.Random;

public class InsertServceImpl implements InsertServce {
    InsertDaoImpl ins=new InsertDaoImpl();
    @Override
    public Page<InsertEntity> findByPage(String name, Integer currentPage) {
        //创建分页对象
        Page<InsertEntity> page=new Page<>();
        //设置每页的行数
        page.setPageSize(10);
        //设置当前行数
        page.setCurrentPage(currentPage);
        //获取总记录调用Dao层区查询
        Integer i=ins.totalCount();
        //调用Dao查询当前页的数据集合
        page.setTotalCount(i);
        Integer start=(currentPage - 1)*page.getPageSize();
        List<InsertEntity> list=ins.list(name,start,page.getPageSize());
        page.setList(list);
        return page;
    }

    @Override
    public boolean findDel(Integer id) {
        int cancel=ins.delete(id);
        if (cancel==1){
            return true;
        }
        return false;
    }
    public static String getRandomString(){
        String str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String str2="0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        int number=random.nextInt(26);
        int number2=random.nextInt(10);
        sb.append(str.charAt(number));
        sb.append("-");
        sb.append(str2.charAt(number2));

        return sb.toString();
    }
}
